<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <h3>什么是防抖？ 在固定的时间内没有触发事件，会在固定时间结束后触发，如果固定时间内触发事件了，会在延长固定时间再触发 防抖主要利用定时器实现</h3>
  <input type="text" id="ipt" placeholder="防抖">
</body>

<script>
  const oIpt = document.getElementById('ipt')

  function center() {
    console.log("发送数据");
  }
  // - 0.1 

  oIpt.onkeyup = debounce(center, 500);

  function debounce(fn, time) {
    let timer = null
    return function () {
      clearTimeout(timer)
      timer = setTimeout(() => {
        fn()
      }, time)

    }


  }





</script>

</html>